package com.atgm.mall.gmmailproduct.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.atgm.common.constant.EsConstant;
import com.atgm.common.constant.GameConstant;
import com.atgm.common.constant.ProductConstant;
import com.atgm.common.constant.UniqueIdConstant;
import com.atgm.common.exception.BizCodeEnume;
import com.atgm.common.exception.GameException;
import com.atgm.common.utils.GmMallUtils;
import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.Query;
import com.atgm.common.utils.R;
import com.atgm.mall.gmmailproduct.config.MyEsConfig;
import com.atgm.mall.gmmailproduct.dao.GameGoodsDao;
import com.atgm.mall.gmmailproduct.dao.GameTypeDao;
import com.atgm.mall.gmmailproduct.dao.GameTypeRelaDao;
import com.atgm.mall.gmmailproduct.entity.*;
import com.atgm.mall.gmmailproduct.feign.CouponFeignService;
import com.atgm.mall.gmmailproduct.feign.vo.FeignGoodsSaleEntity;
import com.atgm.mall.gmmailproduct.service.GameAttrGroupRelaService;
import com.atgm.mall.gmmailproduct.service.GameGoodsImagesService;
import com.atgm.mall.gmmailproduct.service.GameGoodsService;
import com.atgm.mall.gmmailproduct.service.GameTypeRelaService;
import com.atgm.mall.gmmailproduct.utils.IdGeneratorService;
import com.atgm.mall.gmmailproduct.vo.es.GameEsVo;
import com.atgm.mall.gmmailproduct.vo.req.GameGoodsReqVo;
import com.atgm.mall.gmmailproduct.vo.resp.GameGoodsDetailVo;
import com.atgm.mall.gmmailproduct.vo.resp.GameGoodsVo;
import com.atgm.mall.gmmailproduct.vo.resp.GamePriceRespVo;
import com.atgm.mall.gmmailproduct.vo.resp.OrderGameRespVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;

@Slf4j
@Service
public class GameGoodsServiceImpl extends ServiceImpl<GameGoodsDao, GameGoodsEntity> implements GameGoodsService {

    @Autowired
    @Qualifier("couponFeignService")
    private CouponFeignService couponFeignService;

    @Autowired
    private GameTypeRelaService gameTypeRelaService;

    @Autowired
    private GameGoodsImagesService goodsImagesService;

    @Autowired
    private GameTypeDao gameTypeDao;

    @Autowired
    private GameTypeRelaDao gameTypeRelaDao;

    @Autowired
    private GameAttrGroupRelaService gameAttrGroupRelaService;

    @Autowired
    private IdGeneratorService idGeneratorService;

    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    @Override
    public List<GameGoodsEntity> getGoodsInfoByIds(List<Long> goodsIds) {
        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("game_id", goodsIds);
        List<GameGoodsEntity> list = baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public PageUtils getGoodsInfo(Map<String, Object> params) {
        //es查询名称
        String gameName = (String) params.get("name");  //游戏名称
        List<Long> gameIds = new ArrayList<>();
        if (GmMallUtils.isNotEmpty(gameName)) {
            SearchRequest searchRequest = new SearchRequest();
            searchRequest.indices(EsConstant.GAME_INDEX);  //索引
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

            MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("gameName", gameName);
            searchSourceBuilder.query(matchQueryBuilder);
            searchRequest.source(searchSourceBuilder);
            try {
                SearchResponse search = restHighLevelClient.search(searchRequest, MyEsConfig.COMMON_OPTIONS);
                SearchHits hits = search.getHits();
                if (hits.getHits() != null && hits.getHits().length > 0) {
                    for (SearchHit hit : hits) {
                        String sourceAsString = hit.getSourceAsString();
                        GameEsVo gameEsVo = JSON.parseObject(sourceAsString, GameEsVo.class);
                        gameIds.add(gameEsVo.getGameId());
                    }
                }
            } catch (IOException e) {
                log.error("es检索失败");
            }
        }

        if (GmMallUtils.isNotEmpty(gameName) && GmMallUtils.isEmpty(gameIds)) {
            return null;
        }

        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        if (GmMallUtils.isNotEmpty(gameIds)) {
            queryWrapper.in("game_id", gameIds);
        }
        IPage<GameGoodsEntity> page = this.page(new Query<GameGoodsEntity>().getPage(params), queryWrapper);

        PageUtils pageUtils = new PageUtils(page);
        List<GameGoodsEntity> list = page.getRecords();
        if (GmMallUtils.isEmpty(list)) {
            return null;
        }
        pageUtils.setList(packingGoods(list));
        return pageUtils;
    }

    @Override
    public PageUtils queryGoodsInfoByCond(Map<String, Object> params) {
        //获取请求参数
        String catId = (String) params.get("catId");
        String price = (String) params.get("price");
        String types = (String) params.get("types");
        List<Long> relaGoodsIds = new ArrayList<>();
        if (GmMallUtils.isNotEmpty(types)) {
            String[] split = types.split(",");
            List<Long> typeIds = new ArrayList<>();
            if (split.length > 1) {
                for (String str : split) {
                    typeIds.add(Long.valueOf(str));
                }
            }else {
                typeIds.add(Long.valueOf(types));
            }
            List<GameTypeRelaEntity> goodsTypeRelaEntities = gameTypeRelaService.queryListByTypeIds(typeIds);
            if (GmMallUtils.isNotEmpty(goodsTypeRelaEntities)) {
                //获取游戏商品信息
                relaGoodsIds = goodsTypeRelaEntities.stream().map(GameTypeRelaEntity::getGameId).collect(Collectors.toList());
            }
            if (GmMallUtils.isEmpty(relaGoodsIds)) {
                return null;
            }
        }

        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        if ("0".equals(catId)) {   //全部

        } else if ("1".equals(catId)) {  //畅销
            queryWrapper.orderByDesc("sale_count");
        } else if ("2".equals(catId)) {  //折扣
            //获取折扣状态下的游戏信息
            R r = couponFeignService.getSaleGameIds(params);
            if (0 == r.getCode()) {
                List<Long> gameIds = r.getData(new TypeReference<List<Long>>() {});
                if (GmMallUtils.isNotEmpty(gameIds)) {
                    queryWrapper.in("game_id", gameIds);
                }
            }
        } else if ("3".equals(catId)) {  //最新
            queryWrapper.orderByDesc("release_time"); //发布日期
        } else if ("4".equals(catId)) {  //评分
            queryWrapper.orderByDesc("score");
        }
        if (GmMallUtils.isNotEmpty(relaGoodsIds)) {
            queryWrapper.in("game_id", relaGoodsIds);
        }
        if (GmMallUtils.isNotEmpty(price)) {
            if ("5".equals(price)) {
                queryWrapper.gt("price", new BigDecimal(ProductConstant.priceMap.get(price)));
            }else {
                String priceStr = ProductConstant.priceMap.get(price);
                String[] split = priceStr.split("-");
                queryWrapper.between("price", new BigDecimal(split[0]), new BigDecimal(split[1]));
            }
        }
        IPage<GameGoodsEntity> page = this.page(new Query<GameGoodsEntity>().getPage(params), queryWrapper);
        PageUtils pageUtils = new PageUtils(page);

        List<GameGoodsEntity> list = page.getRecords();
        if (GmMallUtils.isEmpty(list)) {
            return null;
        }
        List<GameGoodsVo> goodsVoList = packingGoods(list);
        pageUtils.setList(goodsVoList);
        return pageUtils;
    }

    @Override
    public GameGoodsDetailVo queryGoodsInfoBYId(Long id) {
        GameGoodsDetailVo gameGoodsDetailVo = new GameGoodsDetailVo();
        //获取游戏商品信息
        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("game_id", id);
        queryWrapper.eq("off_shelf", GameConstant.PUT_SHELF);  //上架状态
        GameGoodsEntity goodsEntity = baseMapper.selectOne(queryWrapper);
        BeanUtils.copyProperties(goodsEntity, gameGoodsDetailVo);
        //获取商品的活动信息
        List<Long> goodsIds = Arrays.asList(id);
        R r = couponFeignService.getGoodsSale(goodsIds);
        List<FeignGoodsSaleEntity> feignGoodsSaleEntityList = null;
        if (0 == r.getCode()) {
            feignGoodsSaleEntityList = r.getData(new TypeReference<List<FeignGoodsSaleEntity>>() {});
        }
        FeignGoodsSaleEntity feignGoodsSaleEntity = null;
        if (GmMallUtils.isNotEmpty(feignGoodsSaleEntityList)) {
            feignGoodsSaleEntity = feignGoodsSaleEntityList.get(0);
        }
        if (feignGoodsSaleEntity != null) {
            gameGoodsDetailVo.setSeckillPrice(feignGoodsSaleEntity.getSeckillPrice());
            gameGoodsDetailVo.setSeckillLimit(feignGoodsSaleEntity.getSeckillLimit());
            gameGoodsDetailVo.setSeckillCount(feignGoodsSaleEntity.getSeckillCount());
        }

        //获取商品图片信息
        List<GameImagesEntity> goodsImagesEntities = goodsImagesService.queryGoodsImagesbyGoodsId(id);
        gameGoodsDetailVo.setImgList(goodsImagesEntities);

        return gameGoodsDetailVo;
    }

    /**
     * 装填返回值
     * @param list
     * @return
     */
    private List<GameGoodsVo> packingGoods(List<GameGoodsEntity> list) {
        List<GameGoodsVo> goodsVoList = new ArrayList<>();

        List<Long> gameIds = list.stream().map(GameGoodsEntity::getGameId).collect(Collectors.toList());
        R r = couponFeignService.getGoodsSale(gameIds);
        List<FeignGoodsSaleEntity> feignGoodsSaleEntityList = null;
        if (0 == r.getCode()) {
            feignGoodsSaleEntityList = r.getData(new TypeReference<List<FeignGoodsSaleEntity>>() {});
            log.info("feignGoodsSaleEntityList : {}", feignGoodsSaleEntityList);
        }
        List<Long> goodsSaleIds = new ArrayList<>();
        if (GmMallUtils.isNotEmpty(feignGoodsSaleEntityList)) {
            //获取优惠的商品id
            goodsSaleIds = feignGoodsSaleEntityList.stream().map(FeignGoodsSaleEntity::getGameId).collect(Collectors.toList());
        }

        //获取游戏类型信息
        QueryWrapper<GameTypeRelaEntity> gameTypeRelaEntityQueryWrapper = new QueryWrapper<>();
        gameTypeRelaEntityQueryWrapper.in("game_id", gameIds);
        List<GameTypeRelaEntity> gameTypeRelaEntities = gameTypeRelaDao.selectList(gameTypeRelaEntityQueryWrapper);
        List<Long> gameTypeGameIds = gameTypeRelaEntities.stream().map(GameTypeRelaEntity::getGameId).collect(Collectors.toList());
        List<Long> gameTypeTypeIds = gameTypeRelaEntities.stream().map(GameTypeRelaEntity::getTypeId).collect(Collectors.toList());

        QueryWrapper<GameTypeEntity> gameTypeEntityQueryWrapper = new QueryWrapper<>();
        gameTypeEntityQueryWrapper.select("type_id", "type_name");
        gameTypeEntityQueryWrapper.in("type_id", gameTypeTypeIds);
        List<GameTypeEntity> gameTypeEntities = gameTypeDao.selectList(gameTypeEntityQueryWrapper);

        //状态返回值
        List<FeignGoodsSaleEntity> finalFeignGoodsSaleEntityList = feignGoodsSaleEntityList;
        List<Long> finalGoodsSaleIds = goodsSaleIds;
        list.forEach(gameEntity -> {
            GameGoodsVo goodsVo = new GameGoodsVo();
            BeanUtils.copyProperties(gameEntity, goodsVo);
            //游戏促销信息
            if (finalGoodsSaleIds.contains(gameEntity.getGameId())) {
                goodsVo.setSeckillPrice(finalFeignGoodsSaleEntityList.stream().filter(feignGoodsSaleEntity ->
                        feignGoodsSaleEntity.getGameId().equals(gameEntity.getGameId())).findAny().get().getSeckillPrice());
                goodsVo.setSeckillLimit(finalFeignGoodsSaleEntityList.stream().filter(feignGoodsSaleEntity ->
                        feignGoodsSaleEntity.getGameId().equals(gameEntity.getGameId())).findAny().get().getSeckillLimit());
                goodsVo.setSeckillCount(finalFeignGoodsSaleEntityList.stream().filter(feignGoodsSaleEntity ->
                        feignGoodsSaleEntity.getGameId().equals(gameEntity.getGameId())).findAny().get().getSeckillCount());
                goodsVo.setSeckillPercentage(finalFeignGoodsSaleEntityList.stream().filter(feignGoodsSaleEntity ->
                        feignGoodsSaleEntity.getGameId().equals(gameEntity.getGameId())).findAny().get().getSeckillPercentage());
            }
            //游戏类型
            if (gameTypeGameIds.contains(gameEntity.getGameId())) {
                List<Long> typeIds = gameTypeRelaEntities.stream().filter(gameTypeRelaEntity -> {
                    return gameTypeRelaEntity.getGameId().equals(gameEntity.getGameId());
                }).map(GameTypeRelaEntity::getTypeId).collect(Collectors.toList());
                goodsVo.setGameTypeList(gameTypeEntities.stream().filter(gameTypeEntity -> typeIds.contains(gameTypeEntity.getTypeId())).collect(Collectors.toList()));
            }
            goodsVoList.add(goodsVo);
        });
        return goodsVoList;
    }

    @Override
    public String saveGameGoodsInfo(GameGoodsReqVo gameGoodsReqVo) {
        String gameName = gameGoodsReqVo.getGameName();
        Integer selectCount = baseMapper.selectCount(new QueryWrapper<GameGoodsEntity>().eq("game_name", gameName));
        if (selectCount >= 1) {
            throw new GameException("该游戏[" + gameName + "]已经存在", BizCodeEnume.ADD_GAME_GOODS.getCode());
        }

        List<String> imgList = gameGoodsReqVo.getImgList();
        if (GmMallUtils.isEmpty(imgList)) {
            throw new GameException("游戏图片集不得为空", BizCodeEnume.ADD_GAME_GOODS.getCode());
        }
        //保存游戏商品信息
        GameGoodsEntity gameGoodsEntity = new GameGoodsEntity();
        BeanUtils.copyProperties(gameGoodsReqVo, gameGoodsEntity);
        //游戏商品分布式唯一id
        Long gameId = idGeneratorService.incrementId(UniqueIdConstant.GAME_SUFFIX);
        gameGoodsEntity.setGameId(gameId);
        gameGoodsEntity.setDefaultImg(imgList.get(0));
        gameGoodsEntity.setOffShelf(GameConstant.OFF_SHELF);  //未上架状态
        gameGoodsEntity.setSaleCount(0L);  //商品销售数量
        gameGoodsEntity.setCreateTime(new Date());
        int count = baseMapper.insert(gameGoodsEntity);
        if (count != 1) {
            throw new GameException("添加游戏商品信息不得为空", BizCodeEnume.ADD_GAME_GOODS.getCode());
        }

        //保存游戏图片集
        CompletableFuture<Void> imageFuture = CompletableFuture.runAsync(() -> {
            List<GameImagesEntity> gameImagesEntities = new ArrayList<>();
            for (int i = 0; i < imgList.size(); i++) {
                GameImagesEntity gameImagesEntity = new GameImagesEntity();
                if (i == 0) {
                    gameImagesEntity.setDefImg(1);
                } else {
                    gameImagesEntity.setDefImg(0);
                }
                gameImagesEntity.setImgUrl(imgList.get(i));
                gameImagesEntity.setImgSort(i);
                gameImagesEntities.add(gameImagesEntity);
                gameImagesEntity.setGoodsId(gameId);
            }
            goodsImagesService.saveBatch(gameImagesEntities);
        }, threadPoolExecutor);

        //保存游戏类型信息
        CompletableFuture<Void> typeFuture = CompletableFuture.runAsync(() -> {
            List<GameTypeRelaEntity> gameTypeRelaEntities = new ArrayList<>();
            List<Long> typeIdList = gameGoodsReqVo.getTypeIdList();
            typeIdList.forEach(id -> {
                GameTypeRelaEntity gameTypeRelaEntity = new GameTypeRelaEntity();
                gameTypeRelaEntity.setGameId(gameId);
                gameTypeRelaEntity.setTypeId(id);
                gameTypeRelaEntities.add(gameTypeRelaEntity);
            });
            gameTypeRelaService.saveBatch(gameTypeRelaEntities);
        }, threadPoolExecutor);

        //保存游戏、属性分组信息
        CompletableFuture<Void> attrGroupFuture = CompletableFuture.runAsync(() -> {
            List<GameAttrGroupRelaEntity> gameAttrGroupRelaEntities = new ArrayList<>();
            List<Long> attrGroupIdList = gameGoodsReqVo.getAttrGroupIdList();
            attrGroupIdList.forEach(id -> {
                GameAttrGroupRelaEntity gameAttrGroupRelaEntity = new GameAttrGroupRelaEntity();
                gameAttrGroupRelaEntity.setGameId(gameId);
                gameAttrGroupRelaEntity.setAttrGroupId(id);
                gameAttrGroupRelaEntities.add(gameAttrGroupRelaEntity);
            });
            gameAttrGroupRelaService.saveBatch(gameAttrGroupRelaEntities);
        }, threadPoolExecutor);

        try {
            CompletableFuture.allOf(imageFuture, typeFuture, attrGroupFuture).get();
        } catch (Exception e) {
            log.error("保存游戏商品失败");
        }

        //添加ES
        GameEsVo gameEsVo = new GameEsVo();
        BeanUtils.copyProperties(gameGoodsEntity, gameEsVo);
        gameEsVo.setGameTypeId(gameGoodsReqVo.getTypeIdList());
        BulkRequest bulkRequest = new BulkRequest();
        //创建索引
        IndexRequest indexRequest = new IndexRequest(EsConstant.GAME_INDEX);
        indexRequest.id(gameEsVo.getGameId().toString());
        String gameEsVoToJsonString = JSON.toJSONString(gameEsVo);
        indexRequest.source(gameEsVoToJsonString, XContentType.JSON);
        bulkRequest.add(indexRequest);
        //es上架
        try {
            BulkResponse bulk = restHighLevelClient.bulk(bulkRequest, MyEsConfig.COMMON_OPTIONS);
            boolean b = bulk.hasFailures();
            if (b) {
                log.error("es上架失败");
            }
        }catch (IOException e) {
            e.printStackTrace();
            log.error("es上架失败");
        }

        return String.valueOf(gameId);
    }

    @Override
    public PageUtils queryOffShelfGames(Map<String, Object> params) {
        String gameId = (String) params.get("gameId");
        String gameName = (String) params.get("gameName");
        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        if (GmMallUtils.isNotEmpty(gameId)) {
            queryWrapper.eq("game_id", gameId);
        }
        if (GmMallUtils.isNotEmpty(gameName)) {
            queryWrapper.like("game_name", gameName);
        }
        queryWrapper.eq("off_shelf", GameConstant.OFF_SHELF);
        IPage<GameGoodsEntity> page = this.page(new Query<GameGoodsEntity>().getPage(params), queryWrapper);

        return new PageUtils(page);
    }

    @Override
    public void updateGameShelf(GameGoodsReqVo gameGoodsReqVo) {
        GameGoodsEntity gameGoodsEntity = new GameGoodsEntity();
        BeanUtils.copyProperties(gameGoodsReqVo, gameGoodsEntity);
        int count = baseMapper.updateById(gameGoodsEntity);
        if (count != 1) {
            throw new GameException("更新游戏上下架状态失败", BizCodeEnume.UPDATE_GAME_GOODS.getCode());
        }
    }

    @Override
    public List<String> queryGameName(String name) {
        if (GmMallUtils.isEmpty(name)) {
            throw new GameException("请输入查询条件", BizCodeEnume.VAILD_EXCEPTION.getCode());
        }

        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("game_name", name);
        List<GameGoodsEntity> list = baseMapper.selectList(queryWrapper);

        List<String> outList = new ArrayList<>();
        if (GmMallUtils.isNotEmpty(list)) {
            outList = list.stream().map(GameGoodsEntity::getGameName).collect(Collectors.toList());
        }

        return outList;
    }

    @Override
    public GameGoodsEntity querySimpleInfoById(Long id) {
        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("game_id", "game_name", "default_img", "price", "sale_count");
        queryWrapper.eq("game_id", id);
        queryWrapper.eq("off_shelf", GameConstant.PUT_SHELF);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<GamePriceRespVo> queryGamePrice(List<Long> gameIds) {
        List<GamePriceRespVo> outList = new ArrayList<>();
        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("game_id", "price");
        queryWrapper.in("game_id", gameIds);
        List<GameGoodsEntity> gameGoodsEntities = baseMapper.selectList(queryWrapper);

        if (GmMallUtils.isNotEmpty(gameGoodsEntities)) {
            gameGoodsEntities.forEach(gameGoodsEntity -> {
                GamePriceRespVo gamePriceRespVo = new GamePriceRespVo();
                gamePriceRespVo.setGameId(gameGoodsEntity.getGameId());
                gamePriceRespVo.setPrice(gameGoodsEntity.getPrice());
                outList.add(gamePriceRespVo);
            });
        }

        R r = couponFeignService.getGoodsSale(gameIds);
        List<FeignGoodsSaleEntity> data = r.getData(new TypeReference<List<FeignGoodsSaleEntity>>() {});
        if (data != null) {
            List<Long> seckillGameIds = data.stream().map(FeignGoodsSaleEntity::getGameId).collect(Collectors.toList());
            outList.forEach(gamePriceRespVo -> {
                if (seckillGameIds.contains(gamePriceRespVo.getGameId())) {
                    gamePriceRespVo.setSeckillPrice(data.stream().filter(feignGoodsSaleEntity -> {
                        return feignGoodsSaleEntity.getGameId().equals(gamePriceRespVo.getGameId());
                    }).findAny().get().getSeckillPrice());
                }
            });
        }

        return outList;
    }

    @Override
    public List<OrderGameRespVo> queryOrderGameInfo(List<Long> gameIds) {
        List<OrderGameRespVo> outList = new ArrayList<>();
        if (GmMallUtils.isEmpty(gameIds)) {
            throw new GameException("入参为空", BizCodeEnume.VAILD_EXCEPTION.getCode());
        }

        QueryWrapper<GameGoodsEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("game_id", "game_name", "default_img", "price", "sale_count");
        queryWrapper.in("game_id", gameIds);
        List<GameGoodsEntity> gameGoodsEntities = baseMapper.selectList(queryWrapper);

        if (GmMallUtils.isNotEmpty(gameGoodsEntities)) {
            gameGoodsEntities.forEach(gameGoodsEntity -> {
                OrderGameRespVo orderGameRespVo = new OrderGameRespVo();
                BeanUtils.copyProperties(gameGoodsEntity, orderGameRespVo);
                outList.add(orderGameRespVo);
            });

            R r = couponFeignService.getGoodsSale(gameIds);
            List<FeignGoodsSaleEntity> feignGoodsSaleEntityList = r.getData(new TypeReference<List<FeignGoodsSaleEntity>>() {});
            if (GmMallUtils.isNotEmpty(feignGoodsSaleEntityList)) {
                List<Long> selectGameIds = feignGoodsSaleEntityList.stream().map(FeignGoodsSaleEntity::getGameId).collect(Collectors.toList());
                outList.forEach(orderGameRespVo -> {
                    if (selectGameIds.contains(orderGameRespVo.getGameId())) {
                        orderGameRespVo.setSeckillPrice(feignGoodsSaleEntityList.stream().filter(feignGoodsSaleEntity -> {
                            return feignGoodsSaleEntity.getGameId().equals(orderGameRespVo.getGameId());
                        }).findAny().get().getSeckillPrice());
                    }
                });
            }
        }

        return outList;
    }
}
